package com.cy.pj.common.web.advice;


import com.cy.pj.common.pojo.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice  //@ControllerAdvice+@Responsebody
public class GlobalExceptionHandler {
    @ExceptionHandler(RuntimeException.class) //传入的异常
    public JsonResult doHandlerRuntimeException(RuntimeException e){  //实际能处理的 异常
        e.printStackTrace(); //输出异常到控制台
        log.error("exception{}",e.getMessage());  //记录日志异常
        return new JsonResult(e);
    }

}
